<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:with="title='分类/标签',active='category'">
<header th:replace="back/header::headerFragment(${title},${active})"></header>
<head>
    <meta th:name="_csrf" th:content="${_csrf.token}"/>
    <!-- 默认的header name是X-CSRF-TOKEN -->
    <meta th:name="_csrf_header" th:content="${_csrf.headerName}"/>
</head>
<body class="fixed-left">
<div id="wrapper">
    <div th:replace="back/header::header-body"></div>

    <th:block>
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
            <div class="modal-dialog" role="document" >
                <div class="modal-content" >
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="hidemod()"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel" value=""></h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <span id="myModalinput" class="col-sm-2" style="margin-top: 5px;"></span>
                        <div class="col-sm-10">
                            <input type="text" value="C++" placeholder=""  class="form-control" >

                        </div></div>
                        <button type="button" class="btn btn-primary" style="margin-top: 10px;width: 50%;margin-left: 25%">保存修改</button>


                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-danger" data-dismiss="modal" style="margin-top: 10px;width: 50%;margin-right: 25%">删除</button>
                    </div>

                </div>
            </div>
        </div>

    </th:block>

    <!--    内容-->
    <div class="content-page">
        <div class="content">
            <div class="container">


                <!--    分类修改-->
                <div class="form-horizontal">
                    <h3>文章分类管理</h3>
                    <hr/>

                    <div class="form-group" >
                        <label class=" control-label col-sm-1"></label>

                        <ul class="col-sm-11" style="font-size:20px;">
                            <th:block th:each="cat : ${categoriesList}">
                                <li><a href="javascript:void(0)" onclick="tagSubmit('cate',this)"><th:block th:text="${cat}"/></a></li>
                            </th:block>
                        </ul>

                    </div>
                </div>
                <!--    标签修改-->
                <div class="form-horizontal">
                    <h3>标签管理</h3>
                    <hr/>

                    <div class="form-group" >
                        <label class=" control-label"></label>

                        <div class="col-sm-11">
                            <th:block th:each="tag : ${tagsList}">

                                <button onclick="tagSubmit('tags',this);" type="button" class="btn btn-success" style="margin-left: 5px;margin-top: 10px;"><th:block th:text="${tag}"/></button>

                            </th:block>
                        </div>

                    </div>
                </div>
                <script>
                    var type;

                    function showmod(){
                        document.getElementById("myModal").setAttribute("class","modal fade in");
                        document.getElementById("myModal").setAttribute("style","display: block;");
                    }
                    function hidemod(){
                        document.getElementById("myModal").setAttribute("class","modal fade");
                        document.getElementById("myModal").removeAttribute("style");

                    }
                    function tagSubmit(str,ev){
                        showmod();
                        if(str=='tags'){
                            type=1;
                            $("#myModalLabel").html('编辑标签');
                            $("#myModalinput").html("<a href='/admin/article?tags="+$(ev).html()+"'>标签名称</a>");

                        }else{
                            type=0;
                            $("#myModalLabel").html('编辑分类');
                            $("#myModalinput").html("<a href='/admin/article?cate="+$(ev).html()+"'>分类名称</a>");
                        }
                        $("#myModalinput").attr("value",$(ev).html());
                        $("#myModal input").val($(ev).html());

                    }
                    $("#myModal .btn-primary").click(function (){
                        if(!($("#myModal input").val().length>0))return ;
                        if(($("#myModal input").val()==$("#myModalinput").attr("value")))return ;
                        hidemod();
                        $.ajax({
                            url:'/admin/setCate?news='+$("#myModal input").val()+'&old='+$("#myModalinput").attr("value")+'&type='+type,

                            success:function(ev){
                                if(ev){
                                    window.location.href=window.location.href;
                                }else{
                                    alert("修改失败");
                                    hidemod();
                                }
                            }
                        });

                    });
                    $("#myModal .btn-danger").click(function (){

                        if(!confirm("你确认要删除该分类以及该分类下的所有文章？")){
                            return ;
                        }
                        hidemod();
                        $.ajax({
                            url:'/admin/delCate?old='+$("#myModalinput").attr("value")+'&type='+type,

                            success:function(ev){
                                if(ev){
                                    window.location.href=window.location.href;
                                }else{
                                    alert("修改失败");
                                    hidemod();
                                }
                            }
                        });

                    });

                </script>

                <div th:replace="back/footer :: footer"></div>
            </div>
        </div>
    </div>
</div>




</body>
</html>